package com.ysd.lis.service.bac.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.bac.BacCulProResult;
import com.ysd.lis.entity.bac.BacStainingOptions;
import com.ysd.lis.mapper.bac.BacCulProResultMapper;
import com.ysd.lis.service.bac.BacCulProResultService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wanghuaixing
 * @since 2024-04-12
 */
@Service
public class BacCulProResultServiceImpl extends ServiceImpl<BacCulProResultMapper, BacCulProResult> implements BacCulProResultService {

    @Autowired
    BacCulProResultMapper bacCulProResultMapper;

    @Override
    public Result deleteBacDescOption(BacCulProResult bacCulProResult) {
        int i = bacCulProResultMapper.deleteById(bacCulProResult.getId());
        if (i > 0) {
            return Result.succ(1, "删除成功", bacCulProResult);
        }
        return Result.fail("删除失败");
    }

    @Override
    public Result findBacDescOptionList(BacCulProResult bacCulProResult) {
        LambdaQueryWrapper<BacCulProResult> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(BacCulProResult::getDelFlag,0);
        if (StringUtils.isNotEmpty(bacCulProResult.getSearchValue())){
            queryWrapper.eq(BacCulProResult::getProResultNo,bacCulProResult.getSearchValue()).or().like(BacCulProResult::getProResultNa,bacCulProResult.getSearchValue());
        }
        List<BacCulProResult> bacCulProResultList = bacCulProResultMapper.selectList(queryWrapper);
        return Result.fail(1,"查询成功",bacCulProResultList);
    }

    @Override
    public Result addBacDescOption(BacCulProResult bacCulProResult) {
        int i = bacCulProResultMapper.insert(bacCulProResult);
        if (i > 0) {
            return Result.succ(1, "新增成功", bacCulProResult);
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result updateBacDescOption(BacCulProResult bacCulProResult) {
        int i = bacCulProResultMapper.updateById(bacCulProResult);
        if (i > 0) {
            return Result.succ(1, "更新成功", bacCulProResult);
        }
        return Result.fail("更新失败");
    }

    @Override
    public Result batchDeleteBacDescOption(List<BacCulProResult> bacCulProResultList) {
        List<String> ids = bacCulProResultList.stream().map(BacCulProResult::getId).collect(Collectors.toList());

        boolean b = this.removeByIds(ids);
        if (b) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail(400, "删除失败", "");
        }
    }
}
